package com.rykj.qxj.rest;

import com.rykj.qxj.server.model.entity.DataDict;
import com.rykj.qxj.server.services.IDataDictService;
import com.rykj.qxj.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据字典
 */
@Log4j
@RestController
@RequestMapping("/v1/dataDict")
@Api(tags="字典配置")
public class DataDictController {

    @Autowired
    private IDataDictService dataDictService;

    @GetMapping("/getDataDictByNum")
    @ApiOperation(value="根据编码获取字典配置",notes ="根据编码获取字典配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictNum", value = "字典编码",paramType = "query")
    })
    public Result getDataDictByNum(@RequestParam(value = "dictNum",required=false) String dictNum){
        try{
            List<DataDict> dataDicts=  dataDictService.getDataDictByNum(dictNum);
            return new Result(dataDicts);
        }catch (Exception e){
            log.error("根据编码获取字典配置失败", e);
            return new Result(false, "根据编码获取字典配置失败");
        }
    }
}
